package com.ruoyi.redtea.dualprevent.controller;


import com.ruoyi.redtea.dualprevent.domain.bo.TrainAnalyseUnitBo;
import com.ruoyi.redtea.dualprevent.domain.entity.TrainAnalyseUnit;
import com.ruoyi.redtea.dualprevent.service.TrainAnalyseUnitService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.web.domain.AjaxResult;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 分析单元(TrainAnalyseUnit)表控制层
 *
 * @author makejava
 * @since 2024-05-14 15:45:47
 */
@RestController
@RequestMapping("trainAnalyseUnit")
public class TrainAnalyseUnitController {

    @Value("${a.b}")
    private String ab;
    /**
     * 服务对象
     */
    @Resource
    private TrainAnalyseUnitService trainAnalyseUnitService;

/*    *//**
     * 分页查询
     *
     * @param trainAnalyseUnit 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     *//*
    @GetMapping
    public ResponseEntity<Page<TrainAnalyseUnit>> queryByPage(TrainAnalyseUnit trainAnalyseUnit, PageRequest pageRequest) {
        return ResponseEntity.ok(this.trainAnalyseUnitService.queryByPage(trainAnalyseUnit, pageRequest));
    }*/

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Long id) {
        System.out.println("配置值："+ab);
        return AjaxResult.success(this.trainAnalyseUnitService.queryById(id));
    }

    /**
     * 新增分析单元数据
     *
     * @param trainAnalyseUnitBo 实体
     * @return 新增结果
     */
    @PostMapping
    public AjaxResult add(@RequestBody TrainAnalyseUnitBo trainAnalyseUnitBo) {
        ArrayList<TrainAnalyseUnitBo> trainAnalyseUnits = new ArrayList<>();
        trainAnalyseUnits.add(trainAnalyseUnitBo);
        return AjaxResult.success(this.trainAnalyseUnitService.insert(trainAnalyseUnits));
    }

    /**
     * 编辑数据
     *
     * @param trainAnalyseUnit 实体
     * @return 编辑结果
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TrainAnalyseUnit trainAnalyseUnit) {
        return AjaxResult.success(this.trainAnalyseUnitService.update(trainAnalyseUnit));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public AjaxResult deleteById(Long id) {
        List<Long> ids = new ArrayList<>();
        ids.add(id);
        return AjaxResult.success(this.trainAnalyseUnitService.deleteByIds(ids));
    }

}

